#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.67])
AC_INIT([proxydns], [0.1], [])
AC_CONFIG_SRCDIR([src/zipper.c])
AC_CONFIG_HEADERS([config.h])


AM_INIT_AUTOMAKE([-Wall -Werror foreign])

LT_INIT
AC_PROG_CC
AC_PROG_LIBTOOL

#AC_PROG_CC will define CFLAGS to "-g -O2"
CFLAGS = "-g -O2 -Werror"

# Checks for libraries.
case "$host" in
*-apple-darwin*)
    CFLAGS+=" -L/opt/local/lib -I/opt/local/include"
    ;;
esac

AC_CHECK_LIB([ldns], [ldns_resolver_new], [], [AC_MSG_ERROR([ldns need])])
AC_CHECK_LIB([log4c], [log4c_init], [], [AC_MSG_ERROR([liblog4c need])])


PKG_CHECK_MODULES(GLIB, [glib-2.0], [], [AC_MSG_ERROR([glib need])])
PKG_CHECK_MODULES(EVENT, [libevent], [], [AC_MSG_ERROR([libevent need])])

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h limits.h malloc.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])

AC_DEFUN([RUBY_CONFIG], [ruby -rrbconfig -e "puts(Config::CONFIG[['$1']])"])

# Check for ruby environment
RUBY_HEADER_FILE_PATH=`RUBY_CONFIG(archdir)`
CFLAGS+=" -I$RUBY_HEADER_FILE_PATH"
AC_CHECK_HEADERS([ruby.h],, AC_MSG_ERROR([Missing ruby.h]))

RUBY_LIB_PATH=`RUBY_CONFIG(libdir)`
RUBY_LINK_ARG=`RUBY_CONFIG(LIBRUBYARG)`
AC_SUBST(RUBY_LIB_PATH)
AC_SUBST(RUBY_LINK_ARG)

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset socket strcasecmp strchr strtoul])


AC_ENABLE([slotstat], [AC_DEFINE([SLOTSTAT], [1], [a timeout event to show the slot and glib hashtable])])

AC_CONFIG_FILES([
    Makefile
    src/Makefile
    test/Makefile
    src_mt/Makefile
    src_cache/Makefile
])
AC_OUTPUT
